<template>
	<view class="container">
		<!-- 顶部标题区 -->
		<view class="header">
			<text class="title">会员专享特权</text>
			<text class="subtitle">开通会员享受专属优惠</text>
		</view>

		<!-- 用户信息区 -->
		<view class="user-info">
			<view class="avatar">
				<image :src="avatar" mode=""></image>
			</view>
			<view class="user-details">
				<text class="phone">手机账户 ({{phone}})</text>
				<text class="member-status">{{vipInfo.id?vipInfo.mark:'当前未开通会员'}}</text>
			</view>
		</view>

		<!-- 会员卡选择区 -->
		<view class="card-section">
			<view class="section-title">
				<text class="icon">👑</text>
				<text class="text">会员卡</text>
			</view>

			<view class="card">
				<view class="card-title">
					<text>年会员卡</text>
					<view class="tag">
						<view class="checkbox">
							<text>✓</text>
						</view>
						<text>推荐</text>
					</view>
				</view>

				<view class="price">¥99<text class="unit">/年</text></view>

				<view class="discount">
					<text class="icon">🏷️</text>
					<text class="text">全场8.5折</text>
				</view>
			</view>
		</view>

		<!-- 会员特权区 -->
		<view class="benefits-section">
			<view class="section-title">
				<text class="icon">🎁</text>
				<text class="text">会员特权</text>
			</view>

			<view class="benefit-list">
				<view class="benefit-item">
					<text class="icon">✓</text>
					<text class="text">全场商品85折优惠</text>
				</view>
				<!-- <view class="benefit-item">
          <text class="icon">✓</text>
          <text class="text">每月2张无门槛优惠券</text>
        </view> -->
				<view class="benefit-item">
					<text class="icon">✓</text>
					<text class="text">专属会员日活动</text>
				</view>
				<view class="benefit-item">
					<text class="icon">✓</text>
					<text class="text">生日月特别惊喜</text>
				</view>
				<view class="benefit-item">
					<text class="icon">✓</text>
					<text class="text">专属客服优先服务</text>
				</view>
			</view>
		</view>

		<!-- 支付按钮 -->
		<view class="pay-button" @click="handlePay" v-if="!vipInfo.id">
			<text>{{ buttonText }}</text>
		</view>

		<!-- 支付方式 -->
		<view class="payment-methods" v-if="!vipInfo.id">
			<text>支持支付方式：</text>
			<view class="methods">
				<text>微信</text>
				<!-- <text>支付宝</text>
        <text>银联</text> -->
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getLevelInfo
	} from '@/api/ticket'
	export default {
		data() {
			return {
				buttonText: "立即开通会员",
				phone: '150xxxx1642',
				avatar: '',
				vipInfo: {},
			};
		},

		onShow() {
			this.getPhoneNumber();
		},
		methods: {
			getPhoneNumber() {
				let userInfo = uni.getStorageSync('userInfo')
				if (!userInfo) {
					uni.showToast({
						title: '请登陆后再来开通会员哦'
					})
				} else {
					this.getIsVipInfo()
					this.phone = userInfo.phone
					this.avatar = userInfo.avatar ??
						'https://sinonc-resource.oss-cn-hangzhou.aliyuncs.com/hengyang/2025/02/27/793b6f2ab6b64a79a052293f70842e5c.png'
				}
			},
			getIsVipInfo() {
				getLevelInfo().then((res) => {
					if (res.status == 200) {
						this.vipInfo = res.data.userLevel
					}
				})
			},
			handlePay() {
				const originalText = this.buttonText;
				this.buttonText = "处理中...";
				const that = this
				// 模拟支付处理
				setTimeout(() => {
					// uni.showToast({
					//   title: '支付成功！会员特权已开通',
					//   icon: 'success',
					//   duration: 2000
					// });
					// this.buttonText = originalText;
					let text = '会员'
					that.buttonText = "立即开通会员";
					uni.navigateTo({
						url: `/pages/shop/GoodsList/index?isVipQualification=1`
					})
				}, 100);
			}
		}
	};
</script>

<style lang="less" scoped>
	@primary-color: #2169D3;
	@light-primary: lighten(@primary-color, 25%);
	@dark-primary: darken(@primary-color, 10%);
	@text-color: #333;
	@light-text: #666;
	@white: #ffffff;
	@light-bg: #f0f7ff;
	@card-shadow: 0 10px 20px rgba(33, 105, 211, 0.15);

	.container {
		padding: 20rpx;
		background: linear-gradient(135deg, #f0f7ff 0%, #e0eeff 100%);
		min-height: 100vh;
		color: @text-color;
	}

	.header {
		background: linear-gradient(to right, @primary-color, @dark-primary);
		padding: 40rpx 30rpx;
		text-align: center;
		color: @white;
		border-radius: 20rpx 20rpx 0 0;

		.title {
			font-size: 38rpx;
			font-weight: bold;
			display: block;
			margin-bottom: 15rpx;
		}

		.subtitle {
			font-size: 28rpx;
			opacity: 0.9;
		}
	}

	.user-info {
		display: flex;
		align-items: center;
		padding: 40rpx 30rpx;
		background: @white;
		margin: 20rpx;
		border-radius: 20rpx;
		box-shadow: @card-shadow;

		.avatar {
			width: 120rpx;
			height: 120rpx;
			border-radius: 50%;
			background: linear-gradient(to right, @primary-color, @dark-primary);
			display: flex;
			align-items: center;
			justify-content: center;
			margin-right: 30rpx;

			image {
				width: 120rpx;
				height: 120rpx;
				object-fit: cover;
				border-radius: 50%;
			}

			.avatar-icon {
				font-size: 60rpx;
				color: @white;
			}
		}

		.user-details {
			flex: 1;

			.phone {
				font-size: 34rpx;
				font-weight: bold;
				display: block;
				margin-bottom: 15rpx;
			}

			.member-status {
				font-size: 28rpx;
				color: @primary-color;
				font-weight: 500;
				background: rgba(33, 105, 211, 0.1);
				padding: 10rpx 20rpx;
				border-radius: 40rpx;
				display: inline-block;
			}
		}
	}

	.card-section {
		background: @white;
		padding: 30rpx;
		margin: 20rpx;
		border-radius: 20rpx;
		box-shadow: @card-shadow;

		.section-title {
			display: flex;
			align-items: center;
			margin-bottom: 30rpx;

			.icon {
				font-size: 40rpx;
				margin-right: 15rpx;
			}

			.text {
				font-size: 34rpx;
				font-weight: bold;
			}
		}

		.card {
			background: linear-gradient(to right, @primary-color, @dark-primary);
			border-radius: 25rpx;
			padding: 40rpx;
			color: @white;
			position: relative;
			overflow: hidden;

			&::before {
				content: "";
				position: absolute;
				top: -100rpx;
				right: -100rpx;
				width: 300rpx;
				height: 300rpx;
				border-radius: 50%;
				background: rgba(255, 255, 255, 0.1);
			}

			&::after {
				content: "";
				position: absolute;
				bottom: -80rpx;
				left: -80rpx;
				width: 250rpx;
				height: 250rpx;
				border-radius: 50%;
				background: rgba(255, 255, 255, 0.1);
			}

			.card-title {
				font-size: 40rpx;
				font-weight: bold;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 30rpx;
				position: relative;
				z-index: 2;

				.tag {
					display: flex;
					align-items: center;
					font-size: 28rpx;

					.checkbox {
						width: 40rpx;
						height: 40rpx;
						background: @white;
						border-radius: 50%;
						display: flex;
						align-items: center;
						justify-content: center;
						margin-right: 15rpx;
						color: @primary-color;
						font-weight: bold;
					}
				}
			}

			.price {
				font-size: 70rpx;
				font-weight: bold;
				margin: 30rpx 0;
				position: relative;
				z-index: 2;

				.unit {
					font-size: 30rpx;
					font-weight: normal;
					margin-left: 10rpx;
				}
			}

			.discount {
				background: rgba(255, 255, 255, 0.2);
				border-radius: 50rpx;
				padding: 15rpx 30rpx;
				font-size: 30rpx;
				font-weight: 500;
				display: inline-flex;
				align-items: center;
				position: relative;
				z-index: 2;

				.icon {
					margin-right: 15rpx;
				}
			}
		}
	}

	.benefits-section {
		background: @white;
		padding: 30rpx;
		margin: 20rpx;
		border-radius: 20rpx;
		box-shadow: @card-shadow;

		.section-title {
			display: flex;
			align-items: center;
			margin-bottom: 30rpx;

			.icon {
				font-size: 40rpx;
				margin-right: 15rpx;
			}

			.text {
				font-size: 34rpx;
				font-weight: bold;
			}
		}

		.benefit-list {
			.benefit-item {
				display: flex;
				align-items: center;
				padding: 25rpx 0;
				border-bottom: 2rpx solid #f0f0f0;
				font-size: 30rpx;

				&:last-child {
					border-bottom: none;
				}

				.icon {
					color: @primary-color;
					font-weight: bold;
					font-size: 36rpx;
					margin-right: 20rpx;
					width: 40rpx;
					text-align: center;
				}
			}
		}
	}

	.pay-button {
		background: linear-gradient(to right, @primary-color, @dark-primary);
		color: @white;
		font-size: 36rpx;
		font-weight: bold;
		padding: 30rpx;
		border-radius: 15rpx;
		text-align: center;
		margin: 40rpx 20rpx 0rpx 20rpx;
		box-shadow: 0 8rpx 20rpx rgba(33, 105, 211, 0.3);
		transition: all 0.3s;
		position: fixed;
		bottom: 0;
		width: 690rpx;
	}

	.pay-button:active {
		transform: translateY(2rpx);
		box-shadow: 0 4rpx 10rpx rgba(33, 105, 211, 0.3);
	}

	.payment-methods {
		text-align: center;
		font-size: 26rpx;
		color: @light-text;
		padding: 20rpx 0 40rpx;

		.methods {
			margin-top: 15rpx;

			text {
				display: inline-block;
				margin: 0 20rpx;
				font-weight: 500;
				color: @text-color;
			}
		}
	}
</style>